#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
const int N=1e3+10;
int n,p,k;
int vis[N];
int dis[N];
vector<pair<int,int>> edge[N];
bool check(int bound)
{
	memset(vis,0,sizeof(vis));
	memset(dis,0x3f,sizeof(dis));
	deque<int> q;
	q.push_front(1);
	dis[1]=0;
	while(q.size())
	{
		int x=q.front();
		q.pop_front();
		if(vis[x])
			continue;
		vis[x]=1;
		for(auto& e:edge[x])
		{
			int v=e.second>bound;
			if(dis[e.first]>dis[x]+v)
			{
				dis[e.first]=dis[x]+v;
				if(v)
					q.push_back(e.first);
				else	
					q.push_front(e.first);
			}
		}
	}
	return dis[n]<=k;
}
int main()
{
	cin>>n>>p>>k;
	
	for(int i=0;i<p;i++)
	{
		int a,b,l;
		cin>>a>>b>>l;
		edge[a].push_back({b,l});
		edge[b].push_back({a,l});
	}
	int l=0,r=1e6+1;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	if(r==1e6+1)
		r=-1;
	cout<<r<<endl;
	return 0;
}
